<template>
  <!-- 导航tab -->
  <div class="tab-list">
    <div
      class="tab-item"
      :class="index == active ? 'activeTabItem' : ''"
      v-for="(item, index) in classifyList"
      :key="index"
      @click="handleTab(item, index)"
    >
      <p
        class="title"
        :style="{
          color: active == index ? propsData.params.subtitleTab.titleColor : propsData.params.subtitleTab.defaultTitleColor,
        }"
      >
        {{ item.title }}
      </p>
      <p
        class="subtitle"
        :class="isCurrent(index) ? 'subtitle-active' : ''"
        :style="{
          color:
            active == index ? propsData.params.subtitleTab.subTitleColor : propsData.params.subtitleTab.defaultSubTitleColor,
          background: isCurrent(index)
            ? propsData.params.subtitleTab.activeColor
            : '',
        }"
      >
        {{ item.subTitle }}
      </p>
      <div class="item-hover">
        <div
          class="edit-box"
          @click.stop="
            handleClassifyTabItem('classifySubtitleControl', item, index)
          "
        >
          <i class="iconfont icon-mokuai-bianji"></i>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "",
  props: {
    propsData: {
      type: Object,
      default: {},
    },
    active: {
      type: Number,
      default: 0,
    },
  },
  data() {
    return {};
  },
  mounted() {},
  watch: {},
  computed: {
    classifyList() {
      if (this.propsData.params.classifyList.length <= 0) {
        let arr = [];
        for (let i = 0; i < 6; i++) {
          let obj = {
            title: "标题",
            subTitle: "副标题",
            link: null,
            data: null,
            dataFrom: "",
            classifyId: "",
          };
          arr.push(obj);
        }
        return arr;
      }

      return this.propsData.params.classifyList;
    },
  },
  methods: {
    // 点击切换tab
    handleTab(item, index) {
      this.$emit("changeTab", { item, index });
    },
    // 点击编辑当前状态
    handleClassifyTabItem(name, item, index) {
      this.handleTab(item, index);
      console.log("点击单个专题导航");
      let data = Object.assign({}, this.propsData);
      data.controlComName = name;
      this.$emit("handleClassifyTabItem", data);
    },
    isCurrent(index) {
      let flag =
        this.active == index &&
        this.propsData.params.tabStyle == 3;
      return flag;
    },
  },
};
</script>

<style lang="scss" scoped>
.tab-list {
  width: 100%;
  height: 50px;
  display: flex;
  align-items: center;
  padding: 0 12px;
  .tab-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-right: 30px;
    flex-shrink: 0;
    position: relative;
    z-index: 2;
    .title {
      font-size: 15px;
      font-family: PingFang SC;
      font-weight: 600;
      line-height: 21px;
      color: #000000;
      margin-bottom: 0;
    }
    .subtitle {
      font-size: 12px;
      font-family: PingFang SC;
      font-weight: 400;
      line-height: 17px;
      color: #888888;
      margin-bottom: 0;
    }
    .subtitle-active {
      padding: 0 4px;
      height: 18px;
      line-height: 18px;
      background: #fa2c1b;
      border-radius: 60px;
      color: #ffffff;
    }
    .item-hover {
      width: 100%;
      height: 100%;
      border: 1px solid #1890fc;
      position: absolute;
      left: 0;
      top: 0;
      display: none;
      .edit-box {
        width: 20px;
        height: 20px;
        background: #1890fc;
        border-radius: 0px 0px 0px 4px;
        display: flex;
        justify-content: center;
        align-items: center;
        cursor: pointer;
        position: absolute;
        right: 0;
        top: 0;
        .iconfont {
          font-size: 18px;
          color: #ffffff;
        }
      }
    }
  }
  .tab-item:hover > .item-hover {
    display: block;
  }
  .activeTabItem {
    p:nth-child(1) {
      color: #fa2c1b;
    }
  }
}
</style>
